Skip to content

fix: error when plural datasource returns empty list #2276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

quixoticmonk
Copy link
Collaborator

@quixoticmonk quixoticmonk commented Apr 24, 2025

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request
  • The resources and data sources in this provider are generated from the CloudFormation schema, so they can only support the actions that the underlying schema supports. For this reason submitted bugs should be limited to defects in the generation and runtime code of the provider. Customizing behavior of the resource, or noting a gap in behavior are not valid bugs and should be submitted as enhancements to AWS via the CloudFormation Open Coverage Roadmap.
  • The below logic would capture any empty results and return an error message.
	if len(resourceDescriptions) == 0 {
		return nil, &tfresource.NotFoundError{Message: "Empty result"}
	}

  • Removed that to return resourceDescriptions always.

Resolves #2225

@quixoticmonk
Copy link
Collaborator Author

Test results.

Resources which exist on the account

config

data "awscc_s3_buckets" "buckets" {}

data "awscc_s3_bucket" "bucket"{
  id = "bedrock-s3-kb"
}

output "buckets" {
  value = data.awscc_s3_buckets.buckets
}

output "bucket" {
  value = data.awscc_s3_bucket.bucket
}

result

data.awscc_s3_buckets.buckets: Reading...
data.awscc_s3_bucket.bucket: Reading...
data.awscc_s3_buckets.buckets: Read complete after 0s [id=us-east-1]
data.awscc_s3_bucket.bucket: Read complete after 1s [id=bedrock-s3-kb]

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

bucket = {
  "accelerate_configuration" = null /* object */
  "access_control" = tostring(null)
  "analytics_configurations" = tolist(null) /* of object */
  "arn" = "arn:aws:s3:::bedrock-s3-kb"
  ....
  "website_url" = "http://bedrock-s3-kb.s3-website-us-east-1.amazonaws.com"
}
buckets = {
  "id" = "us-east-1"
  "ids" = toset([
    "amazon-datazone-############-us-east-1-195545589",
    "amazon-datazone-############-us-east-2-227006654",
    "appstream-app-settings-us-west-2-############-khlc2fbv",
    "aws-cloudtrail-logs-############-26e5a216",
    "aws-glue-assets-############-ap-northeast-1",
    .....
    "ses-events-############-us-west-2",
    "sidewalk-import-############-us-west-2",
    "states-templates-22jhlfuris2pk-us-west-2",
    "statetest-s3",
  ])
}


Resources with no results

Config

data "awscc_appflow_flows" "this" {}

output "flows" {
  value = data.awscc_appflow_flows.this
}

result

data.awscc_appflow_flows.this: Reading...
data.awscc_appflow_flows.this: Read complete after 0s [id=us-east-1]

No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:
flows = {
  "id" = "us-east-1"
  "ids" = toset([])
}

@quixoticmonk quixoticmonk marked this pull request as ready for review April 24, 2025 05:36
@quixoticmonk quixoticmonk requested a review from a team as a code owner April 24, 2025 05:36
@quixoticmonk quixoticmonk marked this pull request as draft April 24, 2025 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Data sources that return lists throw an error when target resources do not exist
1 participant